<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
                <div carousel-item>
                    <div><img id="yellowman1"  src="images/yellowman.png"  style="object-fit:scale-down;" ></div>
                </div>
            <legend>搜索订单</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="demoTable" style="float:right">
                    <label class="layui-form-label">搜索条件</label>
                    <div class="layui-input-inline">
                        <select name="condition" id="select"
                                style="height: 30px;background-color: #bfdce5;border-radius: 5px">
                            <option value="">请选择</option>
                            <option value="1">货物编号</option>
                            <option value="2">用户编号</option>
                            <option value="3">金额</option>
                            <option value="4">类型</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" style="border-radius: 15px;" name="num" id="demoReload"
                               autocomplete="off">
                    </div>
                    <button class="layui-btn" style="border-radius: 15px;background-color: rgb(255,255,255)" data-type="reload">
                        <i class="layui-icon layui-icon-search" style="font-size: 30px; color: #dc42a6;"></i></button>
                </div>
            <!--<div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="order_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">货物编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="good_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="user_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">金额</label>
                            <div class="layui-input-inline">
                                <input type="text" name="amount" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">订单类型</label>
                            <div class="layui-input-block">
                                <select name="order_type" lay-filter="aihao">
                                    <option value=""></option>
                                    <option value="0">饮料</option>
                                    <option value="1" selected="">日用品</option>
                                    <option value="2">玩具</option>
                                    <option value="3">文具</option>
                                    <option value="4">零食</option>
                                    <option value="5">蔬菜</option>
                                    <option value="6">水果</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">付费时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="order_type" id="orderTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>-->
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal  layui-btn-radius data-count-edit" style="background-color: #4fecec"
               lay-event="edit"><i class="layui-form"></i>编辑</a>
            <a class="layui-btn layui-btn-normal  layui-btn-radius data-count-delete" style="background-color: #44d789"
               lay-event="logic-del"> <i class="layui-icon"></i>删除</a>
        </script>

    </div>
</div>



<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            cellHeight: 400,
            elem: '#currentTableId',
            url: 'orders/findByPage',
            //skin: 'nob',// 无边框风格
            toolbar: '#toolbarDemo',
            cellMinWidth: 80,
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'oid', width: 100, title: '订单编号', sort: true},
                {field: 'gid', width: 100, title: '货物编号'},
                {field: 'uid', width: 100, title: '用户编号'},
                {field: 'amount', width: 80, title: '金额'},
                {field: 'otype', width: 100, title: '订单类型', minWidth: 100},
                {field: 'ptime', width: 120, title: '付费时间', minWidth: 100,
                    templet: "<div> {{layui.util.toDateString(d.time,'yyyy-MM-dd') }} </div>"},
                {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                limits: [5, 10, 15, 20, 25],
                limit: 5,
                page: true,
                skin: 'line',
                groups: 1 //只显示 1 个连续页码
                , first: "首页"
                , last: "尾页"
            },
            limits: [5, 10, 15, 20, 50, 100],
            limit: 5,
            page: true,
            skin: 'line'
        });


        // 监听搜索操作
        var $ = layui.$, active = {
            reload: function () {
                var num = $('#demoReload');
                var condition = $('#select')
                //console.log(username.val());
                //执行重载
                table.reload('currentTableId', {
                    page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                        limits: [5, 10, 15, 20, 25],
                        limit: 5,
                        page: true,
                        skin: 'line',
                        groups: 1 //只显示 1 个连续页码
                        , first: "首页"
                        , last: "尾页"
                    }
                    , where: {
                        p: num.val(),
                        l: condition.val()
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

//头工具栏事件
         table.on('toolbar(currentTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'batchDel':
                    var data = checkStatus.data;
                    //layer.alert(JSON.stringify(data));
                    var ids = " ";
                    for (var i = 0; i < data.length; i++) {
                        ids += "&ids=" + data[i].id;
                    }
                    $.get("/orders/batchDel", ids,
                        function (data) {
                            //alert(data);
                            if ("success" == data) {
                                table.reload("currentTableId", {});//重新加载当前表格
                            }
                        });
                    break;
            };
         })
                    /* case 'writeExcel':
                         var data = checkStatus.data;
                         //layer.msg('选中了：'+ data.length + ' 个');

                         //获取选中数据的id
                         var ids = "";

                         for (var i = 0; i < data.length; i++) {
                             ids += "&ids=" + data[i].id;
                         }

                         //location对象的href属性表示跳转到指定路径
                         location.href = "/orders/wirteExcel?ids=" + ids

                         break;
                     case 'writeAll':
                         location.href = "/orders/writeAll"
                         break;
                     case 'getExcelTemplate':
                         //layer.msg(checkStatus.isAll ? '全选': '未全选');

                         location.href = "/excel/orders.xlsx"

                         break;
                     case 'getCheckLength':
                         var data = checkStatus.data;
                         layer.msg('选中了：' + data.length + ' 个');
                         break;
                     case 'isAll':
                         layer.msg(checkStatus.isAll ? '全选' : '未全选');
                         break;

                     //自定义头工具栏右侧图标 - 提示
                     case 'LAYTABLE_TIPS':
                         layer.alert('这是工具栏右侧自定义的一个图标按钮');
                         break;
                 }
                 ;
             });
             //监听表格复选框选择
             table.on('checkbox(currentTableFilter)', function (obj) {
                 console.log(obj)
             });
             function openUrl(url){
                 $("#center").load(url);
             }

             table.on('tool(currentTableFilter)', function (obj) {
                 var data = obj.data;
                 if (obj.event === 'edit') {

                     var index = layer.open({
                         title: '编辑用户',
                         type: 2,
                         shade: 0.2,
                         maxmin:true,
                         shadeClose: true,
                         area: ['100%', '100%'],
                         content: '../page/table/edit.html',
                     });
                     $(window).on("resize", function () {
                         layer.full(index);
                     });
                     return false;
                 } else if (obj.event === 'delete') {
                     layer.confirm('真的删除行么', function (index) {
                         obj.del();
                         layer.close(index);
                     });
                 }
             });


         });*/

        //监听行工具事件

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            console.log(data);
            console.log(data.oid + "-----------------");
            if (obj.event === 'edit') {
                queryOne(data);
            } else if (obj.event === 'logic-del') {
                //修改操作
                layer.msg("删除成功")
                var deleteId = data.oid;
                $.get("/orders/logicDelete", {oid: deleteId},
                    function (data) {
                        if ("success" == data) {
                            table.reload("currentTableId", {});//重新加载当前表格
                        }
                    });
            }
        });
    })







</script>

<script type="text/html" id="img">
    <div><img src="{{d.urls}}" style="object-fit: scale-down;border-radius: 50px"></div>
</script>
<script type="text/html" id="updateOrdersForm">

    <form class="layui-form" id="updateOrder">

        <!-- 把oid 作为隐藏域传过去 -->
        <input type="hidden" name="oid" id="oid">

        <div class="layui-form-item">
            <label class="layui-form-label">货物编号</label>
            <div class="layui-input-inline">
                <input type="text" name="gid" id="gid" required lay-verify="required"
                       placeholder="请输入货物编号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户编号</label>
            <div class="layui-input-inline">
                <input type="text" name="uid" id="uid" required lay-verify="required"
                       placeholder="请输入用户编号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">金额</label>
            <div class="layui-input-inline">
                <input type="text" name="amount" id="amount" required lay-verify="required"
                       placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">订单类型</label>
                <div class="layui-inline">
                    <select name="otype" lay-filter="aihao">
                        <option value=""></option>
                        <option value="1"selected="">饮料</option>
                        <option value="2" >日用品</option>
                        <option value="3">玩具</option>
                        <option value="4">文具</option>
                        <option value="5">零食</option>
                        <option value="6">蔬菜</option>
                        <option value="7">水果</option>
                        <option value="8">家具</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">付费时间</label>
                <div class="layui-input-inline">
                    <input type="date" name="ptime" id="ptime" lay-verify="date" placeholder="yyyy-MM-dd"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </form>

</script>
<script>
    function queryOne(data) {
        layer.open({
            type: 1,
            content: $("#updateOrdersForm").html(),
            title: ['修改页面', 'font-size:18px;'],
            area: ['600px', '600px'],
            success: function () {
                $("#oid").val(data.oid);
                $("#gid").val(data.gid);
                $("#uid").val(data.uid);
                $("#amount").val(data.amount);
                $("#otype").val(data.otype);
                $("#ptime").val(data.ptime);
                //渲染页面
                layui.form.render();
            },


            btn: ['提交', '取消']
            , yes: function (index, layero) {

                //修改操作
                $.get("/orders/updateOrder", $("#updateOrder").serialize(),
                    function (data) {
                        if ("success" == data) {
                            location.reload();//刷新当前页面
                        }

                        //修改成功的弹框
                        layer.close('修改成功');
                    });

            }
            , btn2: function (index, layero) {
                alert("取消")
            }
        });
    }
</script>
<!--<script>
    layui.order('carousel', function () {
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test10'
            , width: '100%' //设置容器宽度
            , height:'80'
            , arrow: 'hover' //始终显示箭头
            , anim: 'fade' //切换动画方式
            , autoplay: true
            , interval: 3000

        });
    });
</script>-->
</body>
<style>
    .layui-table-cell {
        height: auto;
        line-height: 35px;
    }
</style>
</html>